import Base from './Base'
import Page from './Page'
import ProductStocksIndexType from './ProductStocksIndexType'

class ProductStocksIndex extends Base {
  constructor ({
    id = '',
    productStocksIndexType = new ProductStocksIndexType({}),
    newestNetvalue = '',
    lastestDate = ''
  }) {
    super({id})
    this.$name = 'product/stock_index'

    this.productStocksIndexType = productStocksIndexType
    this.newestNetvalue = newestNetvalue
    this.lastestDate = lastestDate
  }
  // 获取分页列表
  static async find (params) {
    let {content, ...pagination} = await ProductStocksIndex.$http.get(`${ProductStocksIndex.$name}/listByProductId/${params.typeId}`, {params})
    content = content.map(v => new this(v))
    pagination = new Page(pagination)
    return {content, pagination}
  }
  // 获取所有净值
  static async findAll (params) {
    let res = await ProductStocksIndex.$http.get(`${ProductStocksIndex.$name}/list/${params.typeId}`, {params})
    return res
  }
  // 获取所有类型的最新净值分页列表
  static async findNew (params) {
    let {content, ...pagination} = await ProductStocksIndex.$http.get(`${ProductStocksIndex.$name}/newest`, {params})
    content = content.map(v => new this(v))
    pagination = new Page(pagination)
    return {content, pagination}
  }
}
// 静态属性
ProductStocksIndex.$name = '/product/stocks_index'
export default ProductStocksIndex
